package com.example.service.Imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.b_pojo.BRole;
import com.example.dao.mapper.BRoleMapper;
import com.example.service.BRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BRoleServiceImp implements BRoleService {

    @Autowired
    private BRoleMapper bRoleMapper;


    @Override
    public Page<BRole> hasdelectlist(int pageNum, int pageSize) {
        Page<BRole> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<BRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(BRole.class,p -> !p.getColumn().equals("menuslist"));
        return bRoleMapper.selectPage(page, queryWrapper);
    }

    @Override
    public Page<BRole> alllist(int pageNum, int pageSize) {
        Page<BRole> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<BRole> queryWrapper = new LambdaQueryWrapper<>();
        Page<BRole> bRolePage = bRoleMapper.selectAllRole(page, queryWrapper);
        return bRolePage;
    }

    @Override
    public boolean insertRole(BRole role) {
        return bRoleMapper.insert(role) > 0;
    }

    @Override
    public boolean deleteRole(Long id) {
        return bRoleMapper.deleteById(id) > 0;
    }

    @Override
    public int updateRole(Long id) {
        return 0;
    }

    @Override
    public int updateRoleByRoleId(Long id) {
        return 0;
    }

    @Override
    public BRole getrole(Long id) {
        LambdaQueryWrapper<BRole> wapper = new LambdaQueryWrapper<>();
        wapper.eq(BRole::getId, id)
                .select(BRole.class,p -> !p.getColumn().equals("menuslist"));
        BRole bRole = bRoleMapper.selectOne(wapper);
        return bRole;
    }

    @Override
    public boolean updateRole(BRole bRole) {
        LambdaUpdateWrapper<BRole> wapper = new LambdaUpdateWrapper<>();
        if (bRoleMapper.updateById(bRole) > 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean insertRoleandPermission(Long id, Long permissionId) {
        return bRoleMapper.insertRoleandPermission(id, permissionId)>0;
    }

    @Override
    public boolean delectRoleandPermission(Long id, Long permissionId) {
        return bRoleMapper.delectRoleandPermission(id) >0 ;
    }

    @Override
    public boolean startRoleByRoleId(Long id) {
        int i=bRoleMapper.startRoleByRoleId(id);
        if (i>0){
            return true;
        }
        return false;
    }
}
